#include<bits/stdc++.h>
using namespace std;


int main() {
	int ret = 0;
	string s;
	cin >> s;
	int a[30]{};
	
	for(int i = 0; i < s.size(); i ++ ) {
		a[s[i] - 'A'] = i;	
	}
	
	for(int i = 1; i < 26; i ++ ) {
		ret += abs(a[i] - a[i - 1]);
	}
	
	cout << ret << endl;
	return 0;
}

